package mk.jug.cloud.cms.dao;

import mk.jug.cloud.cms.model.Article;
import org.springframework.stereotype.Repository;

import javax.persistence.EntityManager;
import javax.persistence.Query;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: Ice.Penov
 * Date: 6/8/11
 * Time: 1:28 PM
 * To change this template use File | Settings | File Templates.
 */
@Repository
public class ArticleDAO extends GenericDAO<Article> {

    public List<Article> findAll(final int start, final int end) {
            return new QueryEMContext<List<Article>>() {
                @Override
                public List<Article> query(EntityManager em) {
                    Query query = em.createQuery("Select a from Article a");
                    query.setFirstResult(start);
                    query.setMaxResults(end);
                    return query.getResultList();
                }
            }.result();
    }

}